#include <cstdio>

char map[ 5 ][ 5 ];
int n, num[ 2 ][ 5 ][ 5 ], t, match[ 33 ];
bool hide[ 33 ][ 33 ], check[ 33 ];

void init( )
{
    int i, j;
    t = -1;
    for ( i = 0; i < n; i++ )
        scanf("%s", map[ i ]);
    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < n; j++ )
            if ( map[ i ][ j ] != 'X' )
            {
                if ( j != 0 )
                {
                    if ( map[ i ][ j - 1 ] == 'X' )
                        t++;
                }
                else
                    t++;
                num[ 0 ][ i ][ j ] = t;
            }
    }
    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < n; j++ )
            if ( map[ j ][ i ] != 'X' )
            {
                if ( j != 0 )
                {
                    if ( map[ j - 1 ][ i ] == 'X' )
                        t++;
                }
                else
                    t++;
                num[ 1 ][ j ][ i ] = t;
            }
    }
    for ( i = 0; i <= t; i++ )
    {
        match[ i ] = -1;
        for ( j = 0; j <= t; j++ )
            hide[ i ][ j ] = false;
    }
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ )
            if ( map[ i ][ j ] != 'X' )
                hide[ num[ 0 ][ i ][ j ] ][ num[ 1 ][ i ][ j ] ] = true;
}

bool dfs( int p )
{
    int i, tmp;
    for ( i = 0; i <= t; i++ )
        if ( hide[ i ][ p ] && !check[ i ] )
        {
            check[ i ] = true;
            tmp = match[ i ];
            match[ i ] = p;
            if ( tmp == -1 || dfs( tmp ) )
                return true;
            match[ i ] = tmp;
        }
    return false;
}

void work( )
{
    int i, j, count = 0;
    for ( i = 0; i <= t; i++ )
    {
        for ( j = 0; j <= t; j++ )
            check[ j ] = false;
        if ( dfs( i ) )
            count++;
    }
    printf("%d\n", count);
}

int main( )
{
    while ( scanf("%d",&n) && n )
    {
        init( );
        work( );
    }
    return 0;
}
